package com.fyyg.common.lottery;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.alibaba.fastjson.JSON;

/**
 * @author hang.ouyang
 * @date 2016-04-28 9:26
 */
public class LuckNoUtil {

    private  static Random random = new Random();

    /**
     * 生成抽奖码
     * @param size
     * @return
     */
    public static List<Integer> generateLuckNoList(Integer size){
        List<Integer> list = new ArrayList<>(size);
        Integer baseNo = 10000001;
        for (int i = 0; i < size; i++) {
            list.add(baseNo+i);
        }
        return list;
    }

    /**
     * 生成抽奖码对象json
     * @param size
     * @return
     */
    public static String generateLuckNoJson(Integer size){
        List<LuckNoObj> list = new ArrayList<>(size);
        List<Integer> noList = generateLuckNoList(size);
        LuckNoObj obj = null;
        Integer index = 0;
        while(noList.size() > 0){
            index += 1;
            obj = new LuckNoObj();
            Integer randomLuckNo = noList.get(random.nextInt(noList.size()));
            noList.remove(randomLuckNo);
            obj.setI(index);
            obj.setV(randomLuckNo);
            list.add(obj);
            obj = null;
        }
        return JSON.toJSONString(list);
    }



    public static void main(String[] args) {
        String json = generateLuckNoJson(1999);
        System.out.println(json);

    }


}
